package com.example.sqlitelogin;


import static com.example.sqlitelogin.tools.CodeCommandtv.base1;

import android.hardware.ConsumerIrManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.sqlitelogin.tools.CustomWhiteActionBar;
import com.example.sqlitelogin.tools.SmartLightView;

public class LightTwoActivity extends AppCompatActivity {


    private SmartLightView mSmartLightView;
    private ConsumerIrManager IR;
    //判断是否有红外功能
    boolean IRBack;
    private TextView mTvLumin;
    private SeekBar mSbLumin;
    private TextView mTvWarmLight;
    private SeekBar mSbWarmLight;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //状态栏中的文字颜色和图标颜色，需要android系统6.0以上，而且目前只有一种可以修改（一种是深色，一种是浅色即白色）
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            //修改为深色，因为我们把状态栏的背景色修改为主题色白色，默认的文字及图标颜色为白色，导致看不到了。
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
        setContentView(R.layout.activity_light_two);


        CustomWhiteActionBar actionBar5 = findViewById(R.id.action_bar_5);
        actionBar5.setStyle("卧室 灯");
//获取红外控制类

        //获取ConsumerIrManager实例
        IR = (ConsumerIrManager) LightTwoActivity.this.getSystemService(CONSUMER_IR_SERVICE);

        //如果sdk版本大于4.4才进行是否有红外的功能（手机的android版本）
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            IRBack = IR.hasIrEmitter();
            if (!IRBack) {
                Log.e("leo","对不起，该设备上没有红外功能!");
            } else {

                Log.e("leo","红外设备就绪");//可进行下一步操作
            }
        }
        mSmartLightView = (SmartLightView) findViewById(R.id.SmartLightView);
        mSmartLightView.setSmartLightViewOnClickListener(new SmartLightView.SmartLightViewOnClickListener() {
            @Override
            public void lightStatusCallBack(boolean isOpen) {
                Log.e("xuhong", "点击事件回调，当前开灯状态：" + isOpen);
            }
        });

        mTvLumin = (TextView) findViewById(R.id.tvLumin);
        mSbLumin = (SeekBar) findViewById(R.id.sbLumin);
        mTvWarmLight = (TextView) findViewById(R.id.tvWarmLight);
        mSbWarmLight = (SeekBar) findViewById(R.id.sbWarmLight);


        //亮度
        mSbLumin.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                mSmartLightView.setProgressLumin(seekBar.getProgress());
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                mSmartLightView.setProgressTemper(seekBar.getProgress());
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                mSmartLightView.setProgressTemper(seekBar.getProgress());
//                if (IRBack){
//                    IR.transmit(30000,base1);
//                }

            }
        });


        mSbWarmLight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                mSmartLightView.setProgressTemper(seekBar.getProgress());
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                mSmartLightView.setProgressTemper(seekBar.getProgress());
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                mSmartLightView.setProgressTemper(seekBar.getProgress());
            }
        });



    }
}